/**
 *
 */
angular
    .module('baocloud.VPCView')
    .controller('DataViewCtlr', DataViewCtlr);

var echarts = require('echarts');

function DataViewCtlr($scope, $timeout, $element) {
    var $vdata = $element.find('.chart-container')[0];
    //console.log('$vdata-->', $vdata);
    var vdataChart = echarts.init($vdata);
    var app = {};
    option = null;
    var xAxisData = [];
    var data1 = [];
    var data2 = [];

    $timeout(function(){
        console.log('模拟异步数据--->5000');
        var xAxisDataa = [];
        var dataa1 = [];
        var dataa2 = [];
        for (var i = 0; i < 100; i++) {
            xAxisDataa.push('类目' + i);
            dataa1.push((Math.sin(i / 5) * (i / 5 - 10) + i / 6) * 5);
            dataa2.push((Math.cos(i / 5) * (i / 5 - 10) + i / 6) * 5);
        }
        //vdataChart.resize();
        //填入数据
        vdataChart.setOption({
        xAxis: {
            data: xAxisDataa
        },
        series: [{

            data: dataa1
            },{

            data: dataa2
            }]
        });

    },1000);

    option = {
        title: {
            text: '柱状图动画延迟'
        },
        legend: {
            data: ['bar1', 'bar2'],
            align: 'left'
        },
        tooltip: {},
        xAxis: {
            data: xAxisData,
            silent: false,
            splitLine: {
                show: false
            }
        },
        yAxis: {},
        series: [{
            name: 'bar1',
            type: 'bar',
            data: data1,
            animationDelay: function (idx) {
                return idx * 10;
            }
        }, {
            name: 'bar2',
            type: 'bar',
            data: data2,
            animationDelay: function (idx) {
                return idx * 10 + 100;
            }
        }],
        animationEasing: 'elasticOut',
        animationDelayUpdate: function (idx) {
            return idx * 5;
        }
    };
    if (option && typeof option === "object") {
        vdataChart.setOption(option, true);
    }
}